<template>
  <!-- 挂号列表 -->
  <div>
    <!-- 查询条件开始 -->
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="所属部门" prop="deptId">
        <el-select v-model="queryParams.deptId" placeholder="请选择所属部门" clearable size="small" style="width:200px">
          <el-option v-for="d in deptOptions" :key="d.deptId" :label="d.deptName" :value="d.deptId" />
        </el-select>
      </el-form-item>
      <el-form-item label="患者名称" prop="patientName">
        <el-input v-model="queryParams.patientName" placeholder="请输入患者名称" clearable size="small" style="width:200px" />
      </el-form-item>
      <el-form-item label="挂号类型" prop="schedulingType">
        <el-select v-model="queryParams.schedulingType" placeholder="可用状态" clearable size="small" style="width:200px">
          <el-option v-for="dict in schedulingTypeOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="挂号时段" prop="subsectionType">
        <el-select v-model="queryParams.subsectionType" placeholder="挂号时段" clearable size="small" style="width:200px">
          <el-option v-for="dict in subsectionTypeOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="挂号状态" prop="regStatus">
        <el-select v-model="queryParams.regStatus" placeholder="挂号状态" clearable size="small" style="width:200px">
          <el-option v-for="dict in regStatusOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="挂号时间" prop="queryDate">
        <el-date-picker v-model="queryParams.queryDate" size="small" style="width:200px" value-format="yyyy-MM-dd"
          type="date" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryReg">搜索</el-button>
        <el-button type="normal" icon="el-icon-refresh" size="mini" @click="chongzhi">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 查询条件结束 -->

    <!-- 数据表格开始 -->
    <el-table border :data="regTableList">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="right" inline class="demo-table-expand">
            <el-form-item label="挂号ID:">
              <span>{{ props.row.registrationId }}</span>
            </el-form-item>
            <el-form-item label="挂号员:">
              <span>{{ props.row.createBy }}</span>
            </el-form-item>
            <el-form-item label="创建时间:">
              <span>{{ props.row.createTime }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="挂号科室" align="center" prop="deptId" :formatter="deptIdFormatter" />
      <el-table-column label="接诊医生" align="center" prop="doctorName" />
      <el-table-column label="挂号费用" align="center" prop="registrationAmount">
        <!-- <template slot-scope="scope">
          <span>{{ scope.row.registrationAmount | rounding }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="流水编号" align="center" prop="registrationNumber" />
      <el-table-column label="状态" align="center" prop="registrationStatus" :formatter="regStatusFormatter" />
      <el-table-column label="就诊日期" align="center" prop="visitDate" />
      <el-table-column label="挂号类型" align="center" prop="schedulingType" :formatter="schedulingTypeFormatter" />
      <el-table-column label="挂号时段" align="center" prop="subsectionType" :formatter="subsectionTypeFormatter" />
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button v-if="scope.row.registrationStatus == '0'" type="success" icon="el-icon-check" size="mini"
            @click="handleCollect(scope.row)">收费</el-button>
          <el-button v-if="scope.row.registrationStatus == '1'" type="danger" icon="el-icon-close" size="mini"
            @click="handleReturn(scope.row)">退号</el-button>
          <el-button v-if="scope.row.registrationStatus == '0'" type="danger" icon="el-icon-check" size="mini"
            @click="handleInvalid(scope.row)">作废</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 数据表格结束 -->
    <!-- 分页控件开始 -->
    <el-pagination v-show="page.total > 0" @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="page.current" :page-sizes="[5, 10, 15, 20]" :page-size="page.size"
      layout="total, sizes, prev, pager, next, jumper" :total="page.total">
    </el-pagination>
    <!-- 分页控件结束 -->

  </div>
</template>
  
<script>
export default {
  data() {
    return {
      // 头部查询条件
      queryParams: {
        queryDate: new Date()
      },
      page: {
        current: 1,
        size: 5,
        total: 0,
      },

      // 部门名称
      deptOptions: [],
      // 挂号类型 门诊急诊
      schedulingTypeOptions: [],
      // 挂号时段 上下午+晚上
      subsectionTypeOptions: [],
      // 挂号状态 未收费、待就诊...
      regStatusOptions: [],
      // 表格数据
      regTableList: [],
    }
  },
  created() {
    // 加载所有部门
    this.initDept();
    // 加载挂号类型 门诊急诊
    this.initschedulingType();
    // 加载挂号时段 上下午+晚上
    this.initSubsectionType();
    // 挂号状态 未收费、待就诊...
    this.initRegStatus();
    // 挂号列表
    this.initReg();
  },
  methods: {
    // 收费
    handleCollect(row) {
      let registrationId = row.registrationId;

      this.$confirm('确定收费?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.get("/doctor/api/registration/getCollect/" + registrationId).then(row => {
          this.queryReg();
          this.$message.success("收费成功")
        }).catch(() => {
          this.$message.error('收费失败');
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });


    },
    // 退号
    handleReturn(row) {
      let registrationId = row.registrationId;
      this.$confirm('确认退号?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.get("/doctor/api/registration/getReturn/" + registrationId).then(row => {
          this.queryReg();
          this.$message.success("退号成功")
        }).catch(() => {
          this.$message.error('退号失败');
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });



    },
    // 作废
    handleInvalid(row) {
      let registrationId = row.registrationId;

      this.$confirm('确定作废此挂号信息?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.get("/doctor/api/registration/getInvalid/" + registrationId).then(row => {
          this.queryReg();
          this.$message.success("作废成功")
        }).catch(() => {
          this.$message.error('作废失败');
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });


    },
    // 搜索
    queryReg() {
      this.page.current = 1;
      this.initReg();
    },
    chongzhi() {
      this.queryParams = {
        queryDate: new Date()
        
      };
      this.page.current = 1;
      this.initReg();
    },
    // 挂号列表
    initReg() {
      // let myparam={...this.page,...this.queryParams}
      this.queryParams.queryDate = this.moment(this.queryParams.queryDate).format('YYYY-MM-DD')
      this.$axios.post("doctor/api/registration/regList/" + this.page.current + "/" + this.page.size, this.queryParams)
        .then(row => {
          this.regTableList = row.data.data.records;
          this.page.total = row.data.data.total;
        });
    },
    // 加载所有部门
    initDept() {
      this.$axios.get("doctor/system/deptList").then(row => {
        this.deptOptions = row.data.data;
      })
    },
    // 解析 所有部门
    deptIdFormatter(row) {
      let v = row.deptId;
      for (let i = 0; i < this.deptOptions.length; i++) {
        if (this.deptOptions[i].deptId == v) {
          return this.deptOptions[i].deptName;
        }
      }
      return "";
    },
    // 加载挂号类型 门诊急诊
    initschedulingType() {
      this.$axios.get("doctor/system/dictDataByType/his_scheduling_type").then(row => {
        this.schedulingTypeOptions = row.data.data;
      })
    },
    // 解析 加载挂号类型
    schedulingTypeFormatter(row) {
      let v = row.schedulingType;
      return this.formatDict(this.schedulingTypeOptions, v);
    },
    // 加载挂号时段 上下午+晚上
    initSubsectionType() {
      this.$axios.get("doctor/system/dictDataByType/his_subsection_type").then(row => {
        this.subsectionTypeOptions = row.data.data;
      })
    },
    // 解析 加载挂号时段
    subsectionTypeFormatter(row) {
      let v = row.subsectionType;
      return this.formatDict(this.subsectionTypeOptions, v);
    },
    // 挂号状态 未收费、待就诊...
    initRegStatus() {
      this.$axios.get("doctor/system/dictDataByType/his_registration_status").then(row => {
        this.regStatusOptions = row.data.data;
      })
    },
    // 解析 挂号状态
    regStatusFormatter(row) {
      let v = row.registrationStatus;
      return this.formatDict(this.regStatusOptions, v);
    },
    // 每页 ${val} 条
    handleSizeChange(val) {
      this.page.size = val
      this.initReg();
    },
    //   当前页: ${val}
    handleCurrentChange(val) {
      this.page.current = val;
      this.initReg();
    }
  }
}
</script>
  
<style>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>